package com.csjung.games.gamenori.client.ui;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasAlignment;
import com.google.gwt.user.client.ui.Image;

import com.csjung.games.gamenori.client.style.Styles;

public class ImageButton extends Composite implements HasClickHandlers, HasAlignment {

  public ImageButton() {
    this(new Image());
  }

  public ImageButton(AbstractImagePrototype image) {
    this(image.createImage());
  }

  public ImageButton(Image image) {
    initWidget(new WidgetWrapper(image));
    setStyleName(Styles.common().imageButton());
  }
  
  public Image getImage() {
    return (Image) ((WidgetWrapper) getWidget()).getWidget().getWidget(0, 0);
  }
  
  public void setImage(Image image) {
    ((WidgetWrapper) getWidget()).getWidget().setWidget(0, 0, image);
  }
  
  @Override
  public HorizontalAlignmentConstant getHorizontalAlignment() {
    return ((WidgetWrapper) getWidget()).getHorizontalAlignment();
  }

  @Override
  public void setHorizontalAlignment(HorizontalAlignmentConstant align) {
    ((WidgetWrapper) getWidget()).setHorizontalAlignment(align);
    
  }

  @Override
  public VerticalAlignmentConstant getVerticalAlignment() {
    return ((WidgetWrapper) getWidget()).getVerticalAlignment();
  }

  @Override
  public void setVerticalAlignment(VerticalAlignmentConstant align) {
    ((WidgetWrapper) getWidget()).setVerticalAlignment(align);
    
  }

  @Override
  public HandlerRegistration addClickHandler(ClickHandler handler) {
    return addDomHandler(handler, ClickEvent.getType());
  }

}
